Skip to content

Add ability to create test users with magic link logins - #2062

Merged
ml-evs merged 15 commits into
datalab-org:mainfrom
Matgenix:dw/login_name
Sep 25, 2026
Merged

ml-evs merged 15 commits into
datalab-org:mainfrom
Matgenix:dw/login_name

Conversation

@davidwaroquiers

@davidwaroquiers davidwaroquiers commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Added an additional login procedure for dev/tests. This is purposedly simplistic, just a username, and to login, you just click on the user in the list. The goal is to be able to test various access features / groups etc ... without the need to have multiple OAuth logins.

Adapted from the previous PR here: Matgenix#5
In this previous PR, a password credentials existed. Given the actual purpose of this, i.e. just be able to have different authenticated users easily in a purely test/dev environments, the password credentials added unnecessary code.

Logic in datalab for access to items/anything is:
1/ Authentication (who am I)
2/ Tenant access (do i have access to to this datalab instance)
3/ resource-level access control (can I access this specific "object")

This PR allow to kind of "bypass" 1/ and 2/ (not really bypass, just make it super easy for testing/development).

Adapted a bit from the above: now there are two invoke tasks that let you create test users and list them with login links that developers can use to test other accounts.

Closes #1898
Closes #2133

@davidwaroquiers

Copy link
Copy Markdown
Member Author

@jbouquiaux could you test and review (probably more the backend part) this ? Likely we can add something in the dev-docker documentation with the command to add a user with the docker compose (something like "docker compose exec api-dev uv run invoke dev.create-test-user --username gloubs --role user")
@DianaAliabieva could you test and review (probably more the frontend part) this ?

@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.57%. Comparing base (53c6afb) to head (a6d9655).

Files with missing lines Patch % Lines
pydatalab/src/pydatalab/routes/v0_1/auth.py 70.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2062      +/-   ##
==========================================
- Coverage   81.59%   81.57%   -0.02%     
==========================================
  Files          88       88              
  Lines        8481     8489       +8     
==========================================
+ Hits         6920     6925       +5     
- Misses       1561     1564       +3     
Files with missing lines Coverage Δ
pydatalab/src/pydatalab/routes/v0_1/auth.py 81.32% <70.00%> (-0.35%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread webapp/src/components/UnsafeTestingPasswordlessLogin.vue Outdated
@davidwaroquiers
davidwaroquiers marked this pull request as ready for review September 9, 2026 13:04

@ml-evs ml-evs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @davidwaroquiers, thanks for this. We definitely need something that solves this problem but I think I've come down against the idea of adding password-based login in this way.

I think my suggestion would be instead to hook into the email login approach and enable that by default on dev servers. We can then make invoke dev.serve provide an authenticated link with a token for testing the developers "normal" user by default, and an extra invoke task very similar to the one you added here that creates a test-user and prints a token link for the developer.

What do you think? Happy to implement this if you are okay with it, or go back to this idea if you still prefer a password.

@davidwaroquiers

davidwaroquiers commented Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Hi @davidwaroquiers, thanks for this. We definitely need something that solves this problem but I think I've come down against the idea of adding password-based login in this way.

I think my suggestion would be instead to hook into the email login approach and enable that by default on dev servers. We can then make invoke dev.serve provide an authenticated link with a token for testing the developers "normal" user by default, and an extra invoke task very similar to the one you added here that creates a test-user and prints a token link for the developer.

What do you think? Happy to implement this if you are okay with it, or go back to this idea if you still prefer a password.

Hi @ml-evs

Thank you for the message. Just to mention that it is even not with a password it's "easier". Here is with a few screenshots:

1/ Login page:

image

2/ List of clickable passwordless users with some info (their role, the group(s) they belong to):

image

And you just click on the user you want to be logged in. That eases tests with different users with different roles, belonging to different groups, in the future it could also help test group admins, project admins etc ...).

It is quite perpendicular to almost everything in datalab. It only touches four small points:

  • The configuration flag exposed in the /info response (ENABLE_UNSAFE_TESTING_PASSWORDLESS_LOGIN -- could be renamed as it is very long but at least it's clear :D)
  • The invoke dev.create-test-user task (only active when the above flag is True)
  • Two endpoints on the existing AUTH blueprint group: "GET /login/testing-passwordless/users" to get the list of test users, and "POST /login/testing-passwordless" to start the normal Flask login session for the selected (clicked) user
  • The user picker with the buttons shown above
    (note that one thing I did not like is that there was a new testing_passwordless IdentityType... I removed it in the last commit, using a workaround with the email IdentityType)

After a user is selected, everything follows the normal datalab "flow path" (using the Flask login session for access etc ...).

What do you think ?

@ml-evs

ml-evs commented Sep 23, 2026

Copy link
Copy Markdown
Member

Ah sorry, I think I just searched for "password" and thought I was responding to #1898 🙃 I guess my question then becomes whether adding this to the UI itself is that useful, and if it really needs an API route? I'd prefer a task that lists these login users in the terminal and offers login links for each. Do you find the extra UI component that much more useful than having e.g., a few private browser windows logged in as different accounts?

@davidwaroquiers

Copy link
Copy Markdown
Member Author

Ah sorry, I think I just searched for "password" and thought I was responding to #1898 🙃 I guess my question then becomes whether adding this to the UI itself is that useful, and if it really needs an API route? I'd prefer a task that lists these login users in the terminal and offers login links for each. Do you find the extra UI component that much more useful than having e.g., a few private browser windows logged in as different accounts?

Not that much more useful indeed. I think the idea of having one invoke task that gives the list of passwordless users and their "properties" (roles, groups, ...) and the link is all good. I'll remove the UI part. As for the API route, we at least need the one to login no ?

@davidwaroquiers

Copy link
Copy Markdown
Member Author

Done, should be ready for review

@ml-evs

ml-evs commented Sep 24, 2026

Copy link
Copy Markdown
Member

Could you take a look at 95aa6b0 @davidwaroquiers? I think this is the same functionality but without needing any extra config or routes, just lets you trigger token creation using your test accounts and prints the links you would use to login

@davidwaroquiers

Copy link
Copy Markdown
Member Author

Could you take a look at 95aa6b0 @davidwaroquiers? I think this is the same functionality but without needing any extra config or routes, just lets you trigger token creation using your test accounts and prints the links you would use to login

Hi @ml-evs

Thanks! Works perfectly and indeed much better that there is no new route for that. My only "concern"/"question" is about the config option. Correct me if I'm wrong but we can create a test user for "any" deployment in this case. Just wondering if it wouldn't be better to keep the config option as a "gate" to prevent from creating test users in a "normal/production" deployment. When the test-user option is active (or when other security problems are there, e.g. secrets not matching or whatever), there could be a warning banner to inform the user that the deployment is not meant for production because of this or that. What do you think ? I'm fine either way if you think that is not needed (and anyway if we find out later that it would be useful, it can always be added later).

Thanks!

@ml-evs

ml-evs commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Thanks! Works perfectly and indeed much better that there is no new route for that.

Great, I've added it to the end of this PR.

My only "concern"/"question" is about the config option. Correct me if I'm wrong but we can create a test user for "any" deployment in this case. Just wondering if it wouldn't be better to keep the config option as a "gate" to prevent from creating test users in a "normal/production" deployment. When the test-user option is active (or when other security problems are there, e.g. secrets not matching or whatever), there could be a warning banner to inform the user that the deployment is not meant for production because of this or that. What do you think ? I'm fine either way if you think that is not needed (and anyway if we find out later that it would be useful, it can always be added later).

It's a fair point, it needs direct database access (at which point you could do a lot anyway). I've just tweaked this PR so it only creates the token links for emails on the .test TLD and embedded an extra variable in the token's JWT that says it was created in this way, and only lets you login with these links when "TESTING" is enabled. This pre-empts #2121 a little bit, where I'm changing testing to have not affect on auth at all -- this will be the one effect that remains -- letting you login with these test accounts.

It also goes back to only listing users with the .test domain (and renamed back to dev.list-test-users), rather than all users.

@davidwaroquiers

Copy link
Copy Markdown
Member Author

Thanks! Works perfectly and indeed much better that there is no new route for that.

Great, I've added it to the end of this PR.

My only "concern"/"question" is about the config option. Correct me if I'm wrong but we can create a test user for "any" deployment in this case. Just wondering if it wouldn't be better to keep the config option as a "gate" to prevent from creating test users in a "normal/production" deployment. When the test-user option is active (or when other security problems are there, e.g. secrets not matching or whatever), there could be a warning banner to inform the user that the deployment is not meant for production because of this or that. What do you think ? I'm fine either way if you think that is not needed (and anyway if we find out later that it would be useful, it can always be added later).

It's a fair point, it needs direct database access (at which point you could do a lot anyway). I've just tweaked this PR so it only creates the token links for emails on the .test TLD and embedded an extra variable in the token's JWT that says it was created in this way, and only lets you login with these links when "TESTING" is enabled. This pre-empts #2121 a little bit, where I'm changing testing to have not affect on auth at all -- this will be the one effect that remains -- letting you login with these test accounts.

It also goes back to only listing users with the .test domain (and renamed back to dev.list-test-users), rather than all users.

Perfect for me!

Do you want me to make a final review ?

@ml-evs

ml-evs commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Perfect for me!

Do you want me to make a final review ?

If you have time -- just trying to tidy up merge/rebase! I'll also start work on the follow up PRs

@davidwaroquiers davidwaroquiers left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good to me, just one small comment about the tasks, to prevent them from running if TESTING is false maybe (see in the comment) ?
Had to go through #2121 to understand what it was doing because I thought that with TESTING true it would loose the purpose of test users (which is to test users roles, groups, access, ...).

Comment thread pydatalab/tasks.py
Comment thread pydatalab/docs/INSTALL.md
ml-evs
ml-evs previously approved these changes Sep 25, 2026

@ml-evs ml-evs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and initial PR @davidwaroquiers!

@ml-evs

ml-evs commented Sep 25, 2026

Copy link
Copy Markdown
Member

pre-commit.ci run

@ml-evs

ml-evs commented Sep 25, 2026

Copy link
Copy Markdown
Member

pre-commit.ci autofix

@ml-evs ml-evs changed the title Passwordless test login Add ability to create test users with magic link logins Sep 25, 2026
@ml-evs ml-evs added testing For issues/PRs that change how the package is tested API For issues/PRs pertaining to the API labels Sep 25, 2026
@ml-evs
ml-evs enabled auto-merge (squash) September 25, 2026 14:08
@ml-evs
ml-evs merged commit cc5b46b into datalab-org:main Sep 25, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API For issues/PRs pertaining to the API testing For issues/PRs that change how the package is tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a way for developers to more easily test features that require authentication Add simple username/password login for dev/testing

3 participants